package bTree.LeetCode;

import java.util.ArrayList;
import java.util.List;

public class 对角线遍历 {
    public int[] findDiagonalOrder(int[][] mat) {
        int row = mat.length;
        int line = mat[0].length;
        int []res=new int[row*line];
        int cnt=0;
        int maxSum=row+line-2;
        boolean isUp=true;
        for (int i = 0; i <= maxSum; i++) {
            if (isUp){
                for (int i1=i;i1>=0;i1--){
                    if (i1>=row||i-i1>=line){
                        continue;
                    }
                    res[cnt++]=mat[i1][i-i1];
                }
                isUp=false;
            }else {
                for (int i1=0;i1<=i;i1++){
                    if (i1>=row||i-i1>=line){
                        continue;
                    }
                    res[cnt++]=mat[i1][i-i1];
                }
                isUp=true;
            }
        }
        return res;
    }
}